/*
	File:	video/model/AnimationFramer.hpp
	Date:	2013-06-01
	Author:	Asteroth
*/


#ifndef __ZEN_MODEL_ANIMATION_FRAMER_HPP__
#define __ZEN_MODEL_ANIMATION_FRAMER_HPP__

#include "../../math.hpp"

namespace zen {

	namespace video {

		namespace model {


			enum AnimType {
				AnimTypeNone = 0,
				AnimTypeOnce = 1,
				AnimTypeOnceBack = 2,
				AnimTypeLoop = 3,
				AnimTypeLoopBack = 4,
				AnimTypePingPongOnce = 5,
				AnimTypePingPong = 6
			};


			class AnimationFramer {

			public:

				AnimationFramer();
				AnimationFramer(const AnimationFramer &other);
				~AnimationFramer();

				AnimationFramer& operator = (const AnimationFramer &other);

				AnimType getType() const { return type; }
				void setType(AnimType type) { this->type = type; }

				glm::uint getStart() const { return start; }
				void setStart(glm::uint start);

				glm::uint getEnd() const { return end; }
				void setEnd(glm::uint end);

				glm::uint getPosition() const { return position; }
				void setPosition(glm::uint position);

				glm::float32 getSpeed() const { return speed; }
				void setSpeed(glm::float32 speed) { this->speed = speed; }
	
				bool isPaused() const { return paused; }
				void setPaused(bool paused) { this->paused = paused; }

				glm::uint getStartKey() const { return startKey; }
				void setStartKey(glm::uint startKey) { this->startKey = startKey; };

				glm::uint getEndKey() const { return endKey; }
				void setEndKey(glm::uint endKey) { this->endKey = endKey; };
				
				bool update(int interval);

				
			private:

				AnimType type;
				glm::uint start;
				glm::uint end;
				glm::uint position;
				glm::float32 speed;
				bool paused;
				bool ppdir;
				
				// for optimization purposes
				glm::uint startKey;
				glm::uint endKey;

			};

			inline void AnimationFramer::setStart(glm::uint start) {
				this->start = start;
				if (position < start)
					position = start;
				if (end < start)
					end = start;
			}

			inline void AnimationFramer::setEnd(glm::uint end) {
				this->end = end;
				if (position > end)
					position = end;
				if (start > end)
					start = end;
			}

			inline void AnimationFramer::setPosition(glm::uint position) {
				this->position = position;
				if (position < start)
					position = start;
				if (position > end)
					position = end;
			}


		} // namespace model

	} // namespace video

} // namespace zen

#endif // __ZEN_MODEL_ANIMATION_FRAMER_HPP__
